package com.yiwei.hdb.impl;

import android.content.Context;
import android.text.TextUtils;

import com.yiwei.hdb.constant.Const;
import com.yiwei.hdb.http.CallBackListener;
import com.yiwei.hdb.http.InterfaceServer;
import com.yiwei.hdb.http.InfoCallBack;
import com.yiwei.hdb.interfaces.RepayInfo;
import com.yiwei.hdb.model.GoPayModel;
import com.yiwei.hdb.model.LoanDetailModel;
import com.yiwei.hdb.model.OfflinePaymentModel;
import com.yiwei.hdb.model.PayOrderModel;
import com.yiwei.hdb.model.RepayModel;
import com.yiwei.hdb.model.RepayRecordModel;
import com.yiwei.hdb.model.RequestModel;
import com.yiwei.hdb.model.ResponseModel;

import java.util.HashMap;
import java.util.Map;

/**
 * 还钱
 */
public class RepayInfoImpl implements RepayInfo {

    public void getBalanceRepayInfo(Context paramContext, String paramString1, String paramString2, String paramString3, InfoCallBack paramInfoCallBack) {
    }

    public void getGoPayInfo(Context paramContext, String paramString, final InfoCallBack callBack) {
        HashMap localHashMap = new HashMap();
        localHashMap.put("money", paramString);
        RequestModel model = new RequestModel(localHashMap);
        InterfaceServer.getInstance(paramContext.getApplicationContext()).requestInterface(Const.GO_PAY, Const.RequestMethod.POST, model, Const.DEFAULT_TIMEOUT,new CallBackListener<GoPayModel>(GoPayModel.class,callBack));
//                new ResponseListener() {
//            public void onFinishInMainThread(Object paramAnonymousObject) {
//            }
//
//            public void onStartInMainThread(Object paramAnonymousObject) {
//                callBack.onFailure(paramAnonymousObject.toString());
//            }
//
//
//            @Override
//            public void onSuccessInMainThread(int paramAnonymousInt, String paramAnonymousString, Object result) {
//                try {
//                    GoPayModel model = (GoPayModel) result;
//                    callBack.onSuccess(model);
//                    //返回数据接口
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//
//            @Override
//            public Object onSuccessInRequestThread(int statusCode, String content) {
//                try {
//                    return JsonUtil.<GoPayModel>fromJson(content, GoPayModel.class);
//                } catch (Exception e) {
//                    return null;
//                }
//            }
//        });
    }

    public void getNormalRepay(Context paramContext, String paramString1, String paramString2, final InfoCallBack callBack) {
        HashMap localHashMap = new HashMap();
        localHashMap.put("deal_id", paramString1);
        localHashMap.put("keys", paramString2);
        RequestModel model = new RequestModel(localHashMap);
        InterfaceServer.getInstance(paramContext.getApplicationContext()).requestInterface(Const.NORMAL_REPAY, Const.RequestMethod.POST, model, Const.DEFAULT_TIMEOUT,new CallBackListener<ResponseModel>(ResponseModel.class,callBack));
//                new ResponseListener() {
//            public void onFinishInMainThread(Object paramAnonymousObject) {
//            }
//
//            public void onStartInMainThread(Object paramAnonymousObject) {
//                callBack.onFailure(paramAnonymousObject.toString());
//            }
//
//            @Override
//            public void onSuccessInMainThread(int paramAnonymousInt, String paramAnonymousString, Object result) {
//                try {
//                    ResponseModel model = (ResponseModel) result;
//                    if (model.getStatus() == 1)
//                        callBack.onSuccess(model.getMsg());
//                    else callBack.onFailure(model.getMsg());
//                    //返回数据接口
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//
//            @Override
//            public Object onSuccessInRequestThread(int statusCode, String content) {
//                try {
//                    return JsonUtil.<ResponseModel>fromJson(content, ResponseModel.class);
//                } catch (Exception e) {
//                    return null;
//                }
//            }
//        });
    }

    public void getRepayInfo(Context paramContext, final InfoCallBack callBack) {
        Map<String, Object> mapData = new HashMap<String, Object>();
        RequestModel model = new RequestModel(mapData);
        InterfaceServer.getInstance(paramContext.getApplicationContext()).requestInterface(Const.REPAY_INGDEAL, Const.RequestMethod.POST, model, Const.DEFAULT_TIMEOUT, new CallBackListener<RepayModel>(RepayModel.class,callBack));
//                new ResponseListener() {
//            public void onFinishInMainThread(Object paramAnonymousObject) {
//            }
//
//            public void onStartInMainThread(Object paramAnonymousObject) {
//                callBack.onFailure(paramAnonymousObject.toString());
//            }
//
//            @Override
//            public void onSuccessInMainThread(int paramAnonymousInt, String paramAnonymousString, Object result) {
//                try {
//                    RepayModel model = (RepayModel) result;
//                    if (model.getStatus() == 1)
//                        callBack.onSuccess(model);
//                    else callBack.onFailure(model.getMsg());
//                    //返回数据接口
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//
//            @Override
//            public Object onSuccessInRequestThread(int statusCode, String content) {
//                try {
//                    return JsonUtil.<RepayModel>fromJson(content, RepayModel.class);
//                } catch (Exception e) {
//                    return null;
//                }
//            }
//        });
    }

    /**
     * 借款详情
     *
     * @param mContext
     * @param id
     * @param callBack
     */
    @Override
    public void getLoanDetailInfo(Context mContext, String id, final InfoCallBack callBack) {
        HashMap localHashMap = new HashMap();
        localHashMap.put("id", id);
        RequestModel model = new RequestModel(localHashMap);
        InterfaceServer.getInstance(mContext.getApplicationContext()).requestInterface(Const.DEAL_DETAIL, Const.RequestMethod.POST, model, Const.DEFAULT_TIMEOUT,new CallBackListener<LoanDetailModel>(LoanDetailModel.class,callBack));
//                new ResponseListener() {
//            public void onFinishInMainThread(Object paramAnonymousObject) {
//            }
//
//            public void onStartInMainThread(Object paramAnonymousObject) {
//                callBack.onFailure(paramAnonymousObject.toString());
//            }
//
//            @Override
//            public void onSuccessInMainThread(int paramAnonymousInt, String paramAnonymousString, Object result) {
//                try {
//                    LoanDetailModel model = (LoanDetailModel) result;
//                    if (model.getStatus() == 0)
//                        callBack.onFailure(model.getMsg());
//                    else
//                        callBack.onSuccess(model);
//                    //返回数据接口
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//
//            @Override
//            public Object onSuccessInRequestThread(int statusCode, String content) {
//                try {
//                    return JsonUtil.<LoanDetailModel>fromJson(content, LoanDetailModel.class);
//                } catch (Exception e) {
//                    return null;
//                }
//            }
//        });
    }

    /**
     * 获取线下支付信息
     * @param mContext
     * @param callBack
     */
    @Override
    public void getOfflinePayment(Context mContext, final InfoCallBack callBack) {
        HashMap localHashMap = new HashMap();
        RequestModel model = new RequestModel(localHashMap);
        InterfaceServer.getInstance(mContext.getApplicationContext()).requestInterface(Const.GO_PAY_OFFLINE_PAYMENT, Const.RequestMethod.GET, model, Const.DEFAULT_TIMEOUT, new CallBackListener<OfflinePaymentModel>(OfflinePaymentModel.class,callBack));
//                new ResponseListener() {
//            public void onFinishInMainThread(Object paramAnonymousObject) {
//            }
//
//            public void onStartInMainThread(Object object) {
//                callBack.onFailure(object.toString());
//            }
//
//            @Override
//            public void onSuccessInMainThread(int paramAnonymousInt, String paramAnonymousString, Object result) {
//                try {
//                    OfflinePaymentModel model = (OfflinePaymentModel) result;
//                    callBack.onSuccess(model);
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//
//            @Override
//            public Object onSuccessInRequestThread(int statusCode, String content) {
//                try {
//                    return JsonUtil.<OfflinePaymentModel>fromJson(content, OfflinePaymentModel.class);
//                } catch (Exception e) {
//                    return null;
//                }
//            }
//        });
    }

    /**
     * 提交线下支付
     * @param mContext
     * @param notice_id
     * @param type
     * @param photo
     * @param callBack
     */
    @Override
    public void getOfflineInfo(Context mContext, String notice_id, String type, String photo,String bonus_id, final InfoCallBack callBack) {
        HashMap localHashMap = new HashMap();
        localHashMap.put("notice_id", notice_id);
        localHashMap.put("type", type);
        localHashMap.put("photo", photo);
        if(!TextUtils.isEmpty(bonus_id)){
            localHashMap.put("coupon_ids", bonus_id);
        }
        RequestModel model = new RequestModel(localHashMap);
        InterfaceServer.getInstance(mContext.getApplicationContext()).requestInterface(Const.OFFLINE, Const.RequestMethod.POST, model, Const.DEFAULT_TIMEOUT, new CallBackListener<ResponseModel>(ResponseModel.class,callBack));
//                new ResponseListener() {
//            public void onFinishInMainThread(Object paramAnonymousObject) {
//            }
//
//            public void onStartInMainThread(Object paramAnonymousObject) {
//                callBack.onFailure(paramAnonymousObject.toString());
//            }
//
//            @Override
//            public void onSuccessInMainThread(int paramAnonymousInt, String paramAnonymousString, Object result) {
//                try {
//                    ResponseModel model = (ResponseModel) result;
//                    if (model.getStatus() == 0)
//                        callBack.onFailure(model.getMsg());
//                    else
//                        callBack.onSuccess(model);
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//
//            @Override
//            public Object onSuccessInRequestThread(int statusCode, String content) {
//                try {
//                    return JsonUtil.<ResponseModel>fromJson(content, ResponseModel.class);
//                } catch (Exception e) {
//                    return null;
//                }
//            }
//        });
    }







    @Override
    public void getNewOrderInfo(Context mContext,String action, String payment_id, String channel, String money, String offset_money, String coupon_ids,final InfoCallBack callBack) {
        HashMap localHashMap = new HashMap();
        localHashMap.put("action", action);
        localHashMap.put("payment_id", payment_id);
        localHashMap.put("channel", channel);
        localHashMap.put("money", money);
        localHashMap.put("offset_money", offset_money);
        if(!TextUtils.isEmpty(coupon_ids)){
            localHashMap.put("coupon_ids", coupon_ids);
        }

        RequestModel model = new RequestModel(localHashMap);
        InterfaceServer.getInstance(mContext.getApplicationContext()).requestInterface(Const.OFFLINE_NEW_ORDER, Const.RequestMethod.POST, model, Const.DEFAULT_TIMEOUT, new CallBackListener<PayOrderModel>(PayOrderModel.class,callBack));
//                new ResponseListener() {
//            public void onFinishInMainThread(Object paramAnonymousObject) {
//            }
//
//            public void onStartInMainThread(Object paramAnonymousObject) {
//                callBack.onFailure(paramAnonymousObject.toString());
//            }
//
//            @Override
//            public void onSuccessInMainThread(int paramAnonymousInt, String paramAnonymousString, Object result) {
//                try {
//                    ResponseModel model = (ResponseModel) result;
//                    if (model.getStatus() == 0)
//                        callBack.onFailure(model.getMsg());
//                    else
//                        callBack.onSuccess(model);
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//
//            @Override
//            public Object onSuccessInRequestThread(int statusCode, String content) {
//                try {
//                    return JsonUtil.<ResponseModel>fromJson(content, ResponseModel.class);
//                } catch (Exception e) {
//                    return null;
//                }
//            }
//        });
    }










    /**
     * 通知TA
     * @param mContext
     * @param deal_id
     * @param mobile
     * @param callBack
     */
    @Override
    public void getInviteInfo(Context mContext, String deal_id, String mobile, final InfoCallBack callBack) {
        HashMap localHashMap = new HashMap();
        localHashMap.put("deal_id", deal_id);
        localHashMap.put("mobile", mobile);
        RequestModel model = new RequestModel(localHashMap);
        InterfaceServer.getInstance(mContext.getApplicationContext()).requestInterface(Const.REPAY_INVITE, Const.RequestMethod.POST, model, Const.DEFAULT_TIMEOUT,new CallBackListener<ResponseModel>(ResponseModel.class,callBack));
//                new ResponseListener() {
//            public void onFinishInMainThread(Object paramAnonymousObject) {
//            }
//
//            public void onStartInMainThread(Object paramAnonymousObject) {
//                callBack.onFailure(paramAnonymousObject.toString());
//            }
//
//            @Override
//            public void onSuccessInMainThread(int paramAnonymousInt, String paramAnonymousString, Object result) {
//                try {
//                    ResponseModel model = (ResponseModel) result;
//                    if (model.getStatus() == 0)
//                        callBack.onFailure(model.getMsg());
//                    else
//                        callBack.onSuccess(model);
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
//
//            @Override
//            public Object onSuccessInRequestThread(int statusCode, String content) {
//                try {
//                    return JsonUtil.<ResponseModel>fromJson(content, ResponseModel.class);
//                } catch (Exception e) {
//                    return null;
//                }
//            }
//        });
    }


    /**
     * 还款记录
     * @param mContext
     * @param callBack
     */
    @Override
    public void getRepayRecord(Context mContext,  int pageIndex,final InfoCallBack callBack) {
        Map<String, Object> mapData = new HashMap<String, Object>();
        mapData.put("page", pageIndex+"");
        mapData.put("pagesize","20");
        RequestModel model = new RequestModel(mapData);
        InterfaceServer.getInstance(mContext.getApplicationContext()).requestInterface(Const.REPAY_RECORD_LIST, Const.RequestMethod.POST, model, Const.DEFAULT_TIMEOUT, new CallBackListener<ResponseModel>(RepayRecordModel.class, callBack));
    }
    }
